<template>
  <div class="flex flex-col h-full">
    <SearchContainer @search="getData" @reset="() => reset()">
      <a-form ref="formRef" class="form-style-flex" :model="formState">
        <a-form-item name="zjm" class="ml-2">
          <a-input v-model:value="formState.zjm" class="!w-64" placeholder="物品编号/物品名称/助记码/流水单号" />
        </a-form-item>
        <a-form-item name="stdate" label="操作日期" class="ml-3 mr-3">
          <a-range-picker v-model:value="formState.dateRange" format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
        </a-form-item>
      </a-form>
    </SearchContainer>
    <a-card class="mt-2 flex-1">
      <div class="mb-3 flex justify-end">
        <BaseExport type="物资" name="物资消耗查询" code="000367" :search-params="formState">导出</BaseExport>
      </div>
      <BaseTable :loading="loading" column-code="000367" :data-source="tableData" bordered fill :pagination="pagination">
        <template #bodyCell="{ column, index, record }">
          <template v-if="column.dataIndex === 'xh'">
            <div>{{ index + 1 }}</div>
          </template>
          <template v-if="column.dataIndex === 'mc'">
            <MedicineInfo :value="{ mc: record.mc, gg: record.gg, cj: record.cj }" />
          </template>
        </template>
      </BaseTable>
    </a-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import dayjs from 'dayjs'

const formRef = ref(null)
const formState = ref({
  zjm: '',
  dateRange: [dayjs(new Date().setDate(new Date().getDate() - 20)).format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')]
})
const { loading, tableData, getData, pagination } = useTable({
  url: '/oos/psiform/getKcConsumeCheck',
  immediate: true,
  formatParams: () => {
    return {
      stdate: formState.value.dateRange?.[0],
      eddate: formState.value.dateRange?.[1],
      zjm: formState.value.zjm
    }
  }
})
const reset = () => {
  formState.value = {
    zjm: '',
    dateRange: [dayjs(new Date().setDate(new Date().getDate() - 20)).format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')]
  }
  getData()
}
</script>
<style lang="less" scoped>
.ant-picker {
  width: 100%;
}
</style>
